package com.web.cms.pan.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;

import com.web.cms.pan.message.ShareLogRequest;
import com.web.cms.pan.message.ShareLogResponse;
import com.web.cms.pan.model.ShareLog;

/**
 * 共享日志转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年04月09日
 */
public class ShareLogConvertor
{
	private ShareLogConvertor()
	{
	}
	
	public static ShareLog toShareLog(ShareLogRequest request)
	{
		if (request == null)
			return null;
		
		ShareLog shareLog = new ShareLog();
		shareLog.setId(request.getId());
		shareLog.setShareId(request.getShareId());
		shareLog.setUserId(request.getUserId());
		shareLog.setCreateTime(request.getCreateTime());
		return shareLog;
	}
	
	public static List<ShareLog> toShareLog(List<ShareLogRequest> requestList)
	{
		List<ShareLog> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (ShareLogRequest request : requestList)
		{
			list.add(toShareLog(request));
		}
		return list;
	}
	
	public static ShareLogResponse toResponse(ShareLog shareLog)
	{
		if (shareLog == null)
			return null;
		
		ShareLogResponse response = new ShareLogResponse();
		response.setId(shareLog.getId());
		response.setShareId(shareLog.getShareId());
		response.setUserId(shareLog.getUserId());
		response.setCreateTime(shareLog.getCreateTime());
		return response;
	}
	
	public static List<ShareLogResponse> toResponse(List<ShareLog> list)
	{
		List<ShareLogResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (ShareLog shareLog : list)
		{
			responseList.add(toResponse(shareLog));
		}
		return responseList;
	}
	
	public static Map<Integer, ShareLogResponse> toResponse(Map<Integer, ShareLog> map)
	{
		Map<Integer, ShareLogResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, ShareLog> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<ShareLogResponse> toResponse(Page<ShareLog> page)
	{
		if (page == null)
			return null;
		
		Page<ShareLogResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
